import _operate from '@dfeidao/atom-nodejs/db/operate';
// import query from '@dfeidao/atom-nodejs/db/query';

interface Message {
	_id: string;
	connector: string;
	field: string;
	operate: string;
	field_value: string;
	fieldtype: string;
	group_id: string;
	productid: string;
}
export default async function atom(msg: Message, action_id: string, session_id: string) {

	const systemid = '12';
	const operate = msg.operate;
	const group_id = msg.group_id;
	const productid = msg.productid;
	const { exec, update } = _operate(action_id, session_id, systemid);
	// const { exec: e, prepare: p } = query(action_id, session_id, systemid);
	// p('allot_conditions', ['_id', 'connector', 'group_id', 'field', 'operate', 'field_value', 'priority'], { group_id, productid }, 199, 1, [], []);
	// const [data] = await e();
	// const arr = data.map((v: { _id: string; }) => {
	// 	const obj = { _id: v._id, connector: msg.connector };
	// 	return obj;
	// });
	// const arr1 = new Array({
	// 	_id: msg._id,
	// 	connector: msg.connector,
	// 	field: msg.field,
	// 	operate,
	// 	field_value: msg.field_value,
	// 	fieldtype: msg.fieldtype,
	// 	group_id,
	// 	productid
	// });
	// const cdata = arr.concat(arr1);
	// return arr1;
	// cdata.forEach((v) => {
	update('allot_conditions', { _id: msg._id, productid }, {
		// _id: msg._id,
		connector: msg.connector,
		field: msg.field,
		operate,
		field_value: msg.field_value,
		fieldtype: msg.fieldtype,
		group_id,
		productid
	});

	// });
	const res = await exec();
	if (res.code === 1) {
		return 'success';
	} else {
		return 'fail';
	}

}

